﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TVT.DataAccess.Repositories;
using System.Transactions;

namespace TVT.BizLayer.Entities
{
    [Serializable]
    public class Company : BaseEntity<Company>
    {

        #region attribute

        private static DBRepository repository = DBRepository.GetInstance();

        private int id;
        private String name;
        private decimal accountManagmentFee;
        private String telephone;
        private String address;
        private String taxId;
        private List<User> users;
        private decimal perfFee;
        #endregion

        #region property

        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        public String Name
        {
            get { return name; }
            set { name = value; }
        }
        public decimal AccountManagmentFee
        {
            get { return accountManagmentFee; }
            set { accountManagmentFee = value; }
        }
        public decimal PerfFee
        {
            get { return perfFee; }
            set { perfFee = value; }
        }
        public String Telephone
        {
            get { return telephone; }
            set { telephone = value; }
        }
        public String Address
        {
            get { return address; }
            set { address = value; }
        }
        public String TaxId
        {
            get { return taxId; }
            set { taxId = value; }
        }

        public List<User> Users
        {
            get { return users; }
            set { users = value; }
        }


        #endregion

        #region methods

        public override void Insert()
        {
            throw new NotImplementedException();
        }

        public override void Update()
        {
            throw new NotImplementedException();
        }

        public override void Delete()
        {
            Delete(this.id);
        }

        public static void Delete(int id)
        {
        
        }

        public override void Save()
        {
            if (this.id == 0)
            {
                this.Id = repository.SaveCompany(this.name, this.accountManagmentFee, this.telephone, this.address, this.taxId, this.perfFee);
            }
            else
            {
                repository.UpdateCompany(this.id, this.name, this.accountManagmentFee, this.telephone, this.address, this.taxId, this.perfFee);
            }
        }

        public static Company Find(int id)
        {
            return MapToEntity(repository.FindCompanyById(id));
        }

        public static List<Company> FindAll()
        {
            return MapToEntities(repository.FindAllCompanies());
        }
        public static List<Company> FindByUser(Guid guid)
        {
            return MapToEntities(repository.FindCompaniesByUser(guid));
        }

        public static List<Company> FindByIdAccount(int id)
        {
            return MapToEntities(repository.FindCompaniesByIdAccount(id));
        }


        #endregion




        public static void Save(bool isNew, Guid guid, Company company)
        {
            throw new NotImplementedException();
        }
    }
}
